package com.smartao.base.setting;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.smartao.core.dao.BaseDao;
import com.smartao.core.service.BaseEntityService;

@Service
public class SettingServiceImpl extends BaseEntityService<Setting, Long> implements SettingService{

	@Autowired
	private SettingDao settingDao;
	
	@Override
	protected BaseDao<Setting, Long> getDao() {
		return settingDao;
	}

	@Override
	public List<Setting> findAll() {
		return null;
	}

	@Override
	public Setting findByKey(String key) {
		return settingDao.findByKey(key);
	}

	@Override
	public List<Setting> findByModule(Long moduleId) {
		return settingDao.findByModule(moduleId);
	}

	/**
	 * 加载系统中所有设置项
	 */
	@Override
	public HashMap<String,String> loadConfigs() {
		HashMap<String,String> properties = new HashMap<String,String>();
		List<Setting> list = settingDao.findAll();
		for(Setting setting:list){
			properties.put(setting.getSettingKey(), setting.getSettingValue());
		}
		return properties;
	}
	
}
